﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server_NhaSach.DataAccess.HelperLayer;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using System.Data;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class CTDieuChinhKhoDAO
    {
    
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
            set { _error = value; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertCTPDCKho(CTDieuChinhKhoDTO CTPDCK)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[5];
            par[0] = new SqlParameter("@MaPDCK", CTPDCK.MaPDCK);
            par[1] = new SqlParameter("@MaMH", CTPDCK.MaMH);
            par[2] = new SqlParameter("@SoLuongChuyen", CTPDCK.SoLuongChuyen);
            par[3] = new SqlParameter("@DonGia", CTPDCK.DonGia);
            par[4] = new SqlParameter("@ThanhTien", CTPDCK.ThanhTien);
            try
            {
                helper.InsertQuery("sp_Insert_ChiTietDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTPDCKho(CTDieuChinhKhoDTO CTPDCK)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[5];
            par[0] = new SqlParameter("@MaPDCK", CTPDCK.MaPDCK);
            par[1] = new SqlParameter("@MaMH", CTPDCK.MaMH);
            par[2] = new SqlParameter("@SoLuongChuyen", CTPDCK.SoLuongChuyen);
            par[3] = new SqlParameter("@DonGia", CTPDCK.DonGia);
            par[4] = new SqlParameter("@ThanhTien", CTPDCK.ThanhTien);
            try
            {
                helper.UpdateQuery("sp_Update_ChiTietDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTPDCKho(string MaPDCK,string MaMH)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@maPDCK", MaPDCK);
            par[1] = new SqlParameter("@maMH", MaMH);
            try
            {
                helper.DeleteQuery("sp_Delete_ChiTietDieuChinhKho", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTPDCKho()
        {
            helper = new Helper();
            DataSet ds_ctphieu = helper.SelectQuery("sp_LayDS_ChiTietDieuChinhKho");
            return ds_ctphieu;
        }
        #endregion
    }
}